﻿//======================================================================
//
//        Copyright (C) 2015   
//        All rights reserved
//
//        filename : InitializeCard
//        description : 卡片初始化

//        created by XXX at  20150821
//
//======================================================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CardLogistics.Web.Components;
using System.Data;

namespace CardLogistics.Web.MainPage.CardMaking.InitializeCard
{
    public partial class Detail : BasePage
    {
        private static readonly CardLogistics.DAL.CardMaking.CardMaking_CardDemandData DAL = new CardLogistics.DAL.CardMaking.CardMaking_CardDemandData();
        private static readonly CardLogistics.DAL.CardMaking.CardMaking_CardDemandDetailData DDAL = new CardLogistics.DAL.CardMaking.CardMaking_CardDemandDetailData();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                InitControl();
            }
        }
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public void InitControl()
        {
            string _key = Request.QueryString["id"];
            WebUserControl_AppInfo1.InfoID = _key;
            WebUserControl_AppInfo1.UserID = LoggedUser.ID;
            if (!string.IsNullOrEmpty(_key))
            {
                CardLogistics.Model.CardMaking.CardMaking_CardDemand pData = DAL.GetModel(_key);
                SetWebControls(this.Page, pData);
                if (pData!= null)
                {
                    //申请日期
                    if (pData.APPLICADATE != null)
                    {
                        APPLICADATE.Text = DateTime.Parse(pData.APPLICADATE.ToString()).ToString("yyyy-MM-dd");
                    }
                    //需卡日期
                    if (pData.CARDDATE != null)
                    {
                        CARDDATE.Text = DateTime.Parse(pData.CARDDATE.ToString()).ToString("yyyy-MM-dd");
                    }
                }
                DataTable dt = DDAL.GetInfoByDemandId(pData.ID);//查询卡片需求单明细信息
                string detName = ""; ;
                if (dt != null && dt.Rows.Count > 0)
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                        detName += dr["cardtypename"].ToString() + "[" + dr["CARDNUMBER"].ToString() + "];";
                    }
                    PConNo.Text = detName.TrimEnd(';') + "  总数量:" + Convert.ToInt32(dt.Compute("sum(CARDNUMBER)", ""));//卡片类型/数量
                }
            }
        }
    }
}